package com.csun.cmny.provider.service.impl;

import com.csun.cmny.core.support.BaseService;
import com.csun.cmny.provider.dao.OmcLongRangeServiceComplaintMapper;
import com.csun.cmny.provider.model.constant.ServiceOrderComplaintConstant;
import com.csun.cmny.provider.model.domain.OmcLongRangeServiceComplaint;
import com.csun.cmny.provider.model.domain.OmcLongRangeServiceOrder;
import com.csun.cmny.provider.model.dto.longRangeServiceOrder.LongRangeServiceComplaintSaveDto;
import com.csun.cmny.provider.model.dto.longRangeServiceOrder.LongRangeServiceComplaintSelectDto;
import com.csun.cmny.provider.model.vo.longRangeServiceOrder.LongRangeServiceComplaintVo;
import com.csun.cmny.provider.service.OmcLongRangeServiceComplaintService;
import com.csun.cmny.provider.service.OmcLongRangeServiceOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;


@Slf4j
@Service
@Transactional
public class OmcLongRangeServiceComplaintServiceImpl extends BaseService<OmcLongRangeServiceComplaint> implements OmcLongRangeServiceComplaintService {

    @Resource
    private OmcLongRangeServiceOrderService serviceOrderService;
    @Resource
    private OmcLongRangeServiceComplaintMapper complaintMapper;

    @Override
    public int submit(LongRangeServiceComplaintSaveDto serviceComplaintSaveDto) {

        //修改订单的投诉状态
        OmcLongRangeServiceOrder longRangeServiceOrder = new OmcLongRangeServiceOrder();
        longRangeServiceOrder.setId(serviceComplaintSaveDto.getServiceOrderId());
        longRangeServiceOrder.setComplaintStatus(ServiceOrderComplaintConstant.ORDER_COMPLAINT_WAIT);
        int update1 = serviceOrderService.update(longRangeServiceOrder);

        //新增投诉信息
        OmcLongRangeServiceComplaint omcLongRangeServiceComplaint = new OmcLongRangeServiceComplaint();
        BeanUtils.copyProperties(serviceComplaintSaveDto,omcLongRangeServiceComplaint);
        int save = save(omcLongRangeServiceComplaint);

        return save;
    }

    @Override
    public List<LongRangeServiceComplaintVo> selectComplaint(LongRangeServiceComplaintSelectDto longRangeServiceComplaintSelectDto) {
        return complaintMapper.selectComplaint(longRangeServiceComplaintSelectDto);
    }
}
